Ext.namespace("Task.Watch");
Task.Watch.panel = function() {
	this.search_task_name = new Ext.form.TextField({
		fieldLabel : '任务名称',
		width : 120
	});
	
	this.search_plan_title = new Ext.form.TextField({
		fieldLabel : '计划名称',
		width : 120
	});
	
	this.search_dtStart = new Ext.form.DateField( {
		fieldLabel : '任务派发开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_dtEnd = new Ext.form.DateField( {
		fieldLabel : '任务派发结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_cmStart = new Ext.form.DateField( {
		fieldLabel : '任务提交开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_cmEnd = new Ext.form.DateField( {
		fieldLabel : '任务提交结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_planBgStartDate = new Ext.form.DateField( {
		fieldLabel : '计划开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_planBgEndDate = new Ext.form.DateField( {
		fieldLabel : '计划结束时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});
	
	this.search_planEdStartDate = new Ext.form.DateField( {
		fieldLabel : '计划完结开始时间',
		format : 'Y-m-d',
		//readOnly : true,
		width : 120
	});

	this.search_planEdEndDate = new Ext.form.DateField( {
		fieldLabel : '计划完结结束时间',
		format : 'Y-m-d',
		//selectOnFocus : true,
		width : 120
	});
	
	this.search_taskStatus = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','---请选择---'],[0, '草稿'], [1, '下发'], [2, '完成'], [3, '撤销']]
        }),
		fieldLabel : '任务状态',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});
	this.taskName = new Ext.form.TextField({
		fieldLabel : '任务名称',
		width : 120
	});
	this.taskType = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: OMS.TASKORIGIN
        }),
		fieldLabel : '任务类型',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});
	this.finishState = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','请选择'],[0, '已完成'], [1, '未完成'], [2, '第三方已完成'], [3, '第三方未完成']]
        }),
		fieldLabel : '完成情况',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});	
	this.exeDept = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','请选择'],[0, 'AAAA'], [1, 'NNNN']]
        }),
		fieldLabel : '执行部门',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});	
	this.executorName = new Ext.form.TextField({
		fieldLabel : '执行人',
		width : 120
	});
	this.dispatchDept = new Ext.form.ComboBox( {
		store : new Ext.data.ArrayStore({
        	fields: ['id', 'name'],
        	data: [['','请选择'],[0, 'AAAA'], [1, 'NNNN']]
        }),
		fieldLabel : '派发部门',
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		selectOnFocus : true,
		width : 120
	});	
	this.dispatchName = new Ext.form.TextField({
		fieldLabel : '派发人',
		width : 120
	});
	
	this.dispatchTime = new Ext.form.DateField({
		fieldLabel: '派发时间',
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
            disabled:true 
       }
	});
	this.search_form = new Ext.form.FormPanel({
		frame : true,
		labelWidth : 65,
		labelAlign : 'right',
		scope : this,
		buttons : [{text:'查询',scope:this,handler:function(){this.taskStore.load();}},
		           {text:'清空',scope:this,handler:function(){this.search_form.getForm().reset();}}],
		items : [{layout:'column',
				  defaults:{layout:'form',columnWidth:0.25},
				  items:[
				         {items:[this.taskName,this.taskType,this.dispatchTime]},
				         {items:[this.exeDept,this.executorName]},
				         {items:[this.dispatchDept,this.dispatchName]},
				         {items:[this.dispatchDept,this.dispatchName]}   
				         ]}]
	});
	
	this.taskStore = new Ext.data.JsonStore({
		url : '../task/watchTaskPlan.form?timesnap=' + Date.parse(new Date()),
		method : 'POST',
		root : 'result',
		scope : this,
		fields : ['TASK_ID','TASK_TITLE','TASK_CONTENT','TASK_DATE','TASK_COMPLETE_DATE','TASK_FEEDBACK','PLAN_TITLE',
		          'TASK_STATUS','TASK_ORIGIN','TASK_NOTE','TASK_EXECUTOR','DIS_NAME','PLAN_START_DATE','PLAN_END_DATE'],
		listeners : {
			scope : this,
			beforeload : function(thiz){
				thiz.baseParams = {
					taskTitle : this.search_task_name.getValue(),
					dtStart : this.search_dtStart.value,
					dtEnd : this.search_dtEnd.value,
					cmStart : this.search_cmStart.value,
					cmEnd : this.search_cmEnd.value,
					task_status : this.search_taskStatus.getValue(),
					planTitle : this.search_plan_title.getValue(),
					planBgStartDate : this.search_planBgStartDate.value,
					planBgEndDate : this.search_planBgEndDate.value,
					planEdStartDate : this.search_planEdStartDate.value,
					planEdEndDate : this.search_planEdEndDate.value
				};
			}
		}
	});
	
	this.taskGrid = new Ext.grid.GridPanel({
		scope : this,
		width : 900,
		height : 380,
		listeners : {
			rowdblclick : function(grid,rowIndex,e){
				twi.initTaskWatchInfo(grid.store.getAt(rowIndex).data);
			}
		},
		bbar : [{xtype:'paging',
				 pageSize : 15,
				 emptyMsg : '没有符合条件的数据，请重新搜索',
				 displayInfo : true,
				 store : this.taskStore}],
		columns : [{header:'任务名称',dataIndex:'TASK_TITLE'},
		           {header:'任务派发时间',dataIndex:'TASK_DATE'},
		           {header:'任务提交时间',dataIndex:'TASK_COMPLETE_DATE'},
		           {header:'任务状态',dataIndex:'TASK_STATUS',
		        	   renderer:function(value){return OMS.TASKSTATUS[value];}},
		           {header:'任务来源',dataIndex:'TASK_ORIGIN',
		        	   renderer:function(value){return OMS.TASKORIGIN[value];}},
		           {header:'任务派发人',dataIndex:'DIS_NAME'}],
	    store : this.taskStore
	});
	Task.Watch.panel.superclass.constructor.call(this, {
		title:'任务监控',
		layout:'border',
		items:[this.search_form,this.taskGrid]
	});
},
Ext.extend(Task.Watch.panel, Ext.Panel, {
	init:function(){
		alert(1110);
	}
});
Ext.onReady(function() {
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';
    Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif';
    Task.Watch.panel.instance = new Task.Watch.panel();
});



